#include "libAcoustX/core/param/SolveParam_Point.h"
#include "libGeoutils/tool/shape_tool.h"

ax::param::Point::Point()
{
	setTargetBearingCount(8);
	setTargetRangeDistanceKm(10);
	setTargetStartBearingDeg(0);
}

ax::param::Point::~Point()
{
}

std::map<double, ax::param::Line::sptr> ax::param::Point::toLineParams(ax::core::Source::sptr source) const
{
	std::map<double, ax::param::Line::sptr> result;

	if (!source) {
		return result;
	}

	geo::shape::Rectangle rect;
	geo::shape::Coord center(source->getLongitude(), source->getLatitude());

	geo::tool::ShapeTool stool;
	auto calc_result = stool.calculate_circle_points(center, getTargetRangeDistanceKm(),
		getTargetStartBearingDeg(),
		getTargetBearingCount(),
		rect
	);

	for (const auto& loop_coord_angle : calc_result) 
	{
		auto loop_line_param = std::make_shared<ax::param::Line>(*this);
		loop_line_param->setTargetLongitude(loop_coord_angle.first.getLongitude());
		loop_line_param->setTargetLatitude(loop_coord_angle.first.getLatitude());
		result[loop_coord_angle.second] = loop_line_param;
	}

	return result;
}

geo::shape::Rectangle::sptr ax::param::Point::getBound(ax::core::Source::sptr source) const
{
	geo::shape::Rectangle::sptr result;

	if (!source) {
		return result;
	}

	geo::shape::Coord center(source->getLongitude(), source->getLatitude());

	geo::tool::ShapeTool stool;
	stool.calculate_circle_points(center, getTargetRangeDistanceKm(),
		getTargetStartBearingDeg(),
		getTargetBearingCount(),
		*result.get()
	);

	return result;
}
